<?php
class UploadsComponent extends Component {
	public $controller = null;

	public function initialize(Controller $controller) {
		$this->controller = $controller;
	}
	
	public function upload_file($file, $local_path, $newfilename, $overwrite=false){
		$err_msg = '';

		if(file_exists($local_path.$newfilename) && $overwrite == false) return;

		$out = fopen($local_path.$newfilename, 'wb');
		if ($out == FALSE){
			print "File not opened<br>";
			exit;
		}
	
		$ch = curl_init();
	
		curl_setopt($ch, CURLOPT_FILE, $out);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_URL, $file);
	
		curl_exec($ch);
		//echo "<br>Error is : ".curl_error ( $ch);
	
		curl_close($ch);
		//fclose($handle);
	}
}